package com.hongdee.insurance.itemprice.service.impl;

import com.hongdee.insurance.Common;
import com.hongdee.insurance.itemprice.dao.ITInsuranceItemPriceDao;
import com.hongdee.insurance.itemprice.entity.TInsuranceItemPrice;
import com.hongdee.insurance.itemprice.service.ITInsuranceItemPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Mr. Xu on 2017/5/3.
 */
@Service
public class TInsuranceItemPriceServiceImpl implements ITInsuranceItemPriceService {
    @Autowired
    private ITInsuranceItemPriceDao itInsuranceItemPriceDao;
    private String tabName = "T_Insurance_Item_Price";

    /**
     * 保险项目金额维护保存
     *
     * @param data
     * @param uid
     * @throws Exception
     */
    @Override
    public void save(TInsuranceItemPrice data, String uid) throws Exception {
        //新增
        if (data.getId() == null) {
            data.setCreateUser(uid);
            this.itInsuranceItemPriceDao.saveOrUpdate(data);
        }
    }

    /**
     * 保险项目金额维护分页
     *
     * @param uid
     * @param start
     * @param limit
     * @param data
     * @return
     * @throws Exception
     */
    @Override
    public Map page(String uid, String start, String limit, Map data) throws Exception {
        StringBuffer sql = new StringBuffer();
        sql.append("select * from " + tabName);
        List params = new ArrayList();
        Common common = new Common();
        Boolean hasWhere = false;
        //保险项目id
        if (data.get("itemId") != null && !data.get("itemId").equals("")) {
            hasWhere = common.appendWhereIfNeed(sql, hasWhere);
            sql.append(" item_id = ? ");
            params.add(data.get("itemId"));
        }
        //保险项目类型
        if (data.get("itemType") != null && !data.get("itemType").equals("")) {
            hasWhere = common.appendWhereIfNeed(sql, hasWhere);
            sql.append(" item_type = ? ");
            params.add(data.get("itemType"));
        }
        return this.itInsuranceItemPriceDao.page(sql.toString(), params.toArray(), start, limit);
    }

    /**
     * 删除保险项目金额维护
     *
     * @param id
     * @throws Exception
     */
    @Override
    public void del(String id) throws Exception {
        this.itInsuranceItemPriceDao.executeSQL("delete from " + tabName + " where id = ? ", id);
    }

}
